var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
o.AdViewEm = void 0;
var a,
    i,
    n = t("AdView");
(function (t) {
    t[(t.banner = 1)] = "banner";
    t[(t.rewardVedio = 2)] = "rewardVedio";
    t[(t.interstitial = 3)] = "interstitial";
})((a = o.AdViewEm || (o.AdViewEm = {})));
(function (t) {
    t[(t.receive = 0)] = "receive";
})(i || (i = {}));
var r = (function () {
    function t() {
        this.curAdCache = {};
        this.isViewAding = {};
        this.viewAdCount = {};
        this.adWait = {};
        this.haveLastTime = {};
        this.adSuccess = {};
        this.adObj = {};
        this.onceCallBack = {};
        this.devId = "";
        this.idObj = {};
        this.rewardAd = null;
        this.bannerAd = null;
        this.interstitialAd = null;
        this.rewardAdIsOnLoad = !1;
        this.lastTime = 0;
        this.firstReceiveAd = !1;
    }
    t.prototype.getAdData = function (t, e, o) {
        var i = this;
        console.log("----------------- 当前广告模式字节跳动");
        this.haveLastTime[a.interstitial] = Date.now();
        var r = this;
        this.getReceive = function (t) {
            console.log("AdViewAndroid -------------stalkooo------ 激励视频回调" + t);
            r.rewardCallBack(t);
        };
        this.loadReceive = function (t) {
            i.adSuccess[a.rewardVedio] = t;
        };
        this.callDevId = function (t) {
            if ("" != t) {
                i.devId = t;
                n.default.devId = i.devId;
            }
        };
        cc.AndroidAdverting = this;
        this.idObj[a.banner] = t;
        this.idObj[a.rewardVedio] = e;
        this.idObj[a.interstitial] = o;
        this.curAdCache[a.banner] = {
            show: this.showBannerAd.bind(this),
            hide: this.hideBannerAd.bind(this),
            preLoad: this.preLoadBannerAd.bind(this),
            destory: this.destoryBannerAd.bind(this),
            isCanPlay: this.canPlayBanner.bind(this)
        };
        this.curAdCache[a.rewardVedio] = {
            show: this.showRewarVediodAd.bind(this),
            hide: this.hideRewarVediodAd.bind(this),
            preLoad: this.preLoadRewarVediodAd.bind(this),
            destory: this.destoryRewarVediodAd.bind(this),
            isCanPlay: this.canPlayReward.bind(this)
        };
        this.curAdCache[a.interstitial] = {
            show: this.showInterstitial.bind(this),
            hide: this.hideInterstitial.bind(this),
            preLoad: this.preLoadInterstitial.bind(this),
            destory: this.destoryInterstitial.bind(this),
            isCanPlay: this.canPlayInterstitial.bind(this)
        };
        setTimeout(function () {
            i.preLoadBannerAd();
            i.preLoadInterstitial();
            i.preLoadRewarVediodAd();
        }, 5e3);
        return this.curAdCache;
    };
    t.prototype.rewardCallBack = function (t) {
        this.onceCallBack[a.rewardVedio] && this.onceCallBack[a.rewardVedio] && this.onceCallBack[a.rewardVedio](t);
        this.onceCallBack[a.rewardVedio] = null;
    };
    t.prototype.callBack = function (t, e) {
        this.onceCallBack[e] && this.onceCallBack[e] && this.onceCallBack[e](t);
        this.onceCallBack[e] = null;
    };
    t.prototype.canPlayReward = function () {
        return !!this.adSuccess[a.rewardVedio];
    };
    t.prototype.canPlayInterstitial = function () {
        return !!this.adSuccess[a.interstitial];
    };
    t.prototype.canPlayBanner = function () {
        return !!this.adSuccess[a.banner];
    };
    t.prototype.showBannerAd = function (t) {
        void 0 === t && (t = null);
        if (null != this.bannerAd && this.adSuccess[a.banner]) {
            console.log("展示了banner");
            this.bannerAd
                .show()
                .then(function () {
                    console.log("广告显示成功");
                })
                .catch(function (t) {
                    console.log("广告组件出现问题", t);
                });
        }
    };
    t.prototype.doShowBanner = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.showRewarVediodAd = function (t) {
        var e = this;
        void 0 === t && (t = null);
        console.log("开始播放激励视频");
        this.onceCallBack[a.rewardVedio] = t;
        if (null != this.rewardAd && this.adSuccess[a.rewardVedio])
            this.rewardAd
                .show()
                .then(function () {
                    console.log("开始播放激励视频");
                })
                .catch(function (t) {
                    console.log("广告组件出现问题", t);
                    e.rewardAd.load().then(function () {
                        console.log("手动加载成功");
                        e.rewardAd.show();
                    });
                });
        else {
            console.log("广告未创建");
            this.rewardCallBack && this.rewardCallBack(!1);
        }
        this.viewAdCount[a.rewardVedio] = this.getObjCount(this.viewAdCount, a.rewardVedio) + 1;
    };
    t.prototype.showInterstitial = function (t) {
        var e = this;
        void 0 === t && (t = null);
        this.onceCallBack[a.interstitial] = t;
        if (null != this.interstitialAd) {
            this.interstitialAd
                .show()
                .then(function () {
                    console.log("插屏广告展示成功");
                    e.callBack && e.callBack(!0, a.interstitial);
                })
                .catch(function (t) {
                    console.log("插屏广告组件出现问题", t);
                    e.callBack && e.callBack(!1, a.interstitial);
                });
            this.viewAdCount[a.interstitial] = this.getObjCount(this.viewAdCount, a.interstitial) + 1;
        } else console.log("插屏广告播放失败", "未初始化或加载失败");
    };
    t.prototype.hideBannerAd = function (t) {
        void 0 === t && (t = null);
        console.log("隐藏了banner");
        null != this.bannerAd && this.adSuccess[a.banner] && this.bannerAd.hide();
    };
    t.prototype.hideRewarVediodAd = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.hideInterstitial = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.preLoadBannerAd = function (t) {
        void 0 === t && (t = null);
        this.initBannerAd();
    };
    t.prototype.getObjCount = function (t, e) {
        return t[e] ? t[e] : 0;
    };
    t.prototype.preLoadRewarVediodAd = function (t) {
        void 0 === t && (t = null);
        console.log("预加载激励");
        if (Date.now() - this.lastTime > 5e3) {
            this.lastTime = Date.now();
            this.firstReceiveAd = !0;
            if (null == this.rewardAd) {
                console.log("创建一个激励视频");
                this.createRewardAd();
            }
            this.rewardAd.load();
        }
    };
    t.prototype.doShowRewarVediodAd = function (t) {
        void 0 === t && (t = null);
        this.onceCallBack[a.rewardVedio] = t;
        console.log("播放激励视频");
    };
    t.prototype.doShowInterstitial = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.preLoadInterstitial = function (t) {
        void 0 === t && (t = null);
        this.createInsAd();
        this.interstitialAd.load();
    };
    t.prototype.destoryBannerAd = function () {
        this.bannerAd.destroy();
    };
    t.prototype.destoryRewarVediodAd = function () {
        this.rewardAd
            .destroy()
            .then(function () {
                console.log("已销毁广告");
            })
            .catch(function (t) {
                console.log("广告组件出现问题", t);
            });
    };
    t.prototype.destoryInterstitial = function () {
        this.interstitialAd.destroy();
    };
    Object.defineProperty(t.prototype, "Plat", {
        get: function () {
            return window.tt;
        },
        enumerable: !1,
        configurable: !0
    });
    t.prototype.viewData = function (t, e) {
        console.log("QTtAdDo ----------------- " + t, e);
    };
    t.prototype.initBannerAd = function () {
        var t = this,
            e = n.default.Plat.getSystemInfoSync(),
            o = e.windowWidth,
            i = e.windowHeight;
        if (this.idObj[a.banner]) {
            var r = {adUnitId: this.idObj[a.banner]};
            if ("undefined" != typeof n.default.Plat && null == this.bannerAd) {
                this.bannerAd = n.default.Plat.createBannerAd(r);
                this.bannerAd.onLoad(function () {
                    console.log("加载横幅广告成功");
                    t.adSuccess[a.banner] = !0;
                });
                this.bannerAd.onError(function (e) {
                    console.log("加载失败，onError:" + JSON.stringify(e));
                    t.adSuccess[a.banner] = !1;
                });
                this.bannerAd.onResize(function (e) {
                    t.bannerAd.style.top = i - e.height;
                    t.bannerAd.style.left = (o - e.width) / 2;
                });
            }
        } else console.log("横幅广告参数没有配置");
    };
    t.prototype.createRewardAd = function () {
        var t = this;
        console.log("广告id", this.idObj[a.rewardVedio]);
        if (this.idObj[a.rewardVedio]) {
            var e = {
                adUnitId: this.idObj[a.rewardVedio],
                multiton: !1,
                multitonRewardMsg: ["1", "2", "3", "4"],
                multitonRewardTimes: 1,
                progressTip: !1
            };
            if ("undefined" != typeof n.default.Plat && null == this.rewardAd) {
                this.rewardAd = n.default.Plat.createRewardedVideoAd(e);
                this.rewardAd.onLoad(function () {
                    console.log("加载广告成功");
                    t.adSuccess[a.rewardVedio] = !0;
                });
                this.rewardAd.onError(function (e) {
                    console.log("onError:" + JSON.stringify(e));
                    console.log("暂时没广告了");
                    t.adSuccess[a.rewardVedio] = !1;
                    t.rewardCallBack(!1);
                });
                this.rewardAd.onClose(function (e) {
                    console.log("视频广告关闭回调");
                    if (e && e.isEnded) {
                        console.log("正常播放结束，可以下发游戏奖励");
                        t.rewardCallBack(!0);
                    } else {
                        console.log("播放中途退出，不下发游戏奖励");
                        t.rewardCallBack(!1);
                    }
                    e && e.count && console.log("看了" + e.count + "遍");
                    t.adSuccess[a.rewardVedio] = !1;
                });
            }
        } else console.log("视频广告参数没有配置");
    };
    t.prototype.createInsAd = function () {
        var t = this;
        if (this.idObj[a.interstitial]) {
            var e = {adUnitId: this.idObj[a.interstitial]};
            if ("undefined" != typeof n.default.Plat) {
                this.interstitialAd = n.default.Plat.createInterstitialAd(e);
                this.interstitialAd.onLoad(function () {
                    console.log("加载插屏广告成功");
                    t.adSuccess[a.interstitial] = !0;
                });
                this.interstitialAd.onError(function (e) {
                    console.log("onError:" + JSON.stringify(e));
                    t.adSuccess[a.interstitial] = !1;
                });
                this.interstitialAd.onClose(function (e) {
                    console.log("视频广告关闭回调");
                    e && e.isEnded
                        ? console.log("正常播放结束，可以下发游戏奖励")
                        : console.log("播放中途退出，不下发游戏奖励");
                    t.interstitialAd.destroy();
                    t.preLoadInterstitial();
                    t.callBack(!0, a.interstitial);
                });
            }
        } else console.log("视频广告参数没有配置");
    };
    return t;
})();
o.default = r;
